#include <stdio.h>
#include <stdlib.h>
/* tranditional copy file */
int copy_file(const char *src, const char *dst)
{
    FILE *fp_src;
    FILE *fp_dst;

    fp_src = fopen(src, "r");
    if (fp_src == NULL)
        return -1;
    fp_dst = fopen(dst, "w");
    if (fp_dst == NULL) {
        fclose(fp_src);
        return -1;

    }
    size_t file_sz;
    fseek(fp_src, 0, SEEK_END);
    file_sz = ftell(fp_src);
    fseek(fp_src, 0, SEEK_SET);

    void *fbuf = malloc(file_sz);
    if (fbuf == NULL) {
        fclose(fp_src);
        fclose(fp_dst);
        return -1;
    }
    fread(fbuf, file_sz, 1, fp_src);
    fwrite(fbuf, file_sz, 1, fp_dst);

    free(fbuf);
    fclose(fp_src);
    fclose(fp_dst);
    return 0;
}

int main(int argc, char *argv[])
{
    if (!copy_file("hello.txt", "hello2.txt"))
        printf("copy ok!\n");
    else
        printf("copy failed!\n");

    return 0;
}
